#include "Echart.h"
#include "echart_private.h"

#include <stdarg.h>
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/
void echart_dataset_new(Echart_Dataset *ds)
{
	ds->values = eina_array_new(1);
	ds->color = 0xff00ffff;
}
/*============================================================================*
 *                                   API                                      *
 *============================================================================*/
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI void echart_dataset_label_set(Echart_Dataset *ds, const char *label)
{
	ds->label = strdup(label);
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI const char * echart_dataset_label_get(Echart_Dataset *ds)
{
	return ds->label;
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI void echart_dataset_free(Echart_Dataset *ds)
{
	Eina_Array_Iterator iterator;
	unsigned int i;
	double *p;

	EINA_ARRAY_ITER_NEXT(ds->values, i, p, iterator)
		free(p);
	eina_array_free(ds->values);
	if (ds->label) free(ds->label);
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI Echart_Dataset * echart_dataset_next(Echart_Dataset *ds)
{
	return EINA_INLIST_CONTAINER_GET((EINA_INLIST_GET(ds))->next, Echart_Dataset);
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI Echart_Dataset * echart_dataset_prev(Echart_Dataset *ds)
{
	return EINA_INLIST_CONTAINER_GET((EINA_INLIST_GET(ds))->prev, Echart_Dataset);
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI void echart_dataset_value_add(Echart_Dataset *ds, double value)
{
	/* FIXME there must be another way ... */
	double *p;

	p = malloc(sizeof(double));
	*p = value;
	eina_array_push(ds->values, p);
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI void echart_dataset_values_add(Echart_Dataset *ds, int count, ...)
{
	va_list ap;
	double v;

	va_start(ap, count);
	while (count--)
	{
		v = va_arg(ap, double);
		echart_dataset_value_add(ds, v);
	}
	va_end(ap);
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI int echart_dataset_values_get(Echart_Dataset *ds, double **values)
{
	int i;
	int count;

	count = eina_array_count_get(ds->values);
	*values = malloc(sizeof(double) * count);
	/* FIXME there must be another way ... */
	for(i = 0; i < count; i++)
	{
		double *p;

		p = eina_array_data_get(ds->values, i);
		(*values)[i] = *p;
	}

	return count;
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI void echart_dataset_color_set(Echart_Dataset *ds, Echart_Color color)
{
	ds->color = color;
}
/**
 * To be documented
 * FIXME: To be fixed
 */
EAPI Echart_Color echart_dataset_color_get(Echart_Dataset *ds)
{
	return ds->color;
}
